package com.item.service.impl;

import com.github.pagehelper.PageHelper;
import com.item.domain.TableToList;
import com.item.mapper.TableToListMapper;
import com.item.service.TableToListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TableToListServiceImpl implements TableToListService {

    @Autowired
    TableToListMapper tableToListMapper;

    @Override
    public List<TableToList> findAll(int limit, int page, TableToList tableToList) {
        if (limit > 0 && page > 0) {
            PageHelper.startPage(limit, page);
        }
        return tableToListMapper.findAll(tableToList);
    }

    @Override
    public int add(TableToList tableToList) {
        int i = 0;
        try {
            i = tableToListMapper.insertSelective(tableToList);
        } catch (Exception e) {
            return i;
        }
        return i;
    }

    @Override
    public int update(TableToList tableToList) {
        int i = 0;
        try {
            i = tableToListMapper.updateByPrimaryKey(tableToList);
        } catch (Exception e) {
            return i;
        }
        return i;
    }

    @Override
    public int delete(int id) {
        return tableToListMapper.deleteByPrimaryKey(id);
    }
}
